﻿using System;
using System.Collections.Generic;
using System.Text;

namespace daSyntaxAnalyser.SyntaxTree
{
    using daBase.Objects;

    public class TestStatementElement : StatementElement
    {
        private ExpressionElement test;
        private StatementElement iftrue;
        private StatementElement iffalse;

        public ExpressionElement Test { get { return test; } set { test = value; } }
        public StatementElement IfTrue { get { return iftrue; } set { iftrue = value; } }
        public StatementElement IfFalse { get { return iffalse; } set { iffalse = value; } }

        public TestStatementElement(TokenInfo StartInfo, ExpressionElement Test, StatementElement IfTrue, StatementElement IfFalse, List<TokenInfo> Comments)
            : base(StartInfo, Comments)
        {
            test = Test;
            iftrue = IfTrue;
            iffalse = IfFalse;
        }

        public override string ToString()
        {
            string result = string.Format("if {0} then {1}", test, iftrue);
            if (iffalse != null)
                result += string.Format(" {0}", iffalse);
            return result;
        }

        protected override IEnumerator<ISyntaxTreeElement> CreateEnumerator()
        {
            yield return test;
            if (iftrue != null)
                yield return iftrue;
            if (iffalse != null)
                yield return iffalse;
        }
    }
}
